< previous page page_247 next page >

Page 247
Note
If a field name contains blanks, you must enclose it in brackets.

Accessing Multiple Tables
Because of the normalization process, data can be placed in many different tables to reduce the amount of duplicate data. When you need to retrieve this information from the related tables, you need to create a SQL statement that will combine this information. To select data from multiple tables, you need to specify three things:
The table to retrieve the field from
The fields that need to be retrieved
The relationship between the tables
When specifying the fields to be retrieved in the fieldlist, you need to place the table name and a period in front of the field name (for example, Contact.[First Name]). If you need to retrieve some fields from one table and all fields from another, you can still use the wildcard character (for example, Contact.[First Name], Sales.*). The next step is to specify the tables you're using in the FROM clause of the SELECT statement. Finally, the relationship between the tables is specified by using a WHERE clause of a JOIN condition. The WHERE clause is used more often than the JOIN condition when creating SQL statements. The final SQL statement would look like the following:
SELECT Contact.[First Name], Contact.[Last Name], Sales.* FROM Contact,
     Sales WHERE Contact.ID = Sales.ID
This statement retrieves the first and last name from the Contact table and all the related sales information from the Sales table.
Note
You can omit table names from the fieldlist as long as the field name is unique in the tables listed.

Creating Calculated Values
In the preceding SQL example, the sales-related information for each contact is retrieved. Suppose that you also need to work with the average sale made for that contact. You can calculate this value by dividing the two values in your program code, or you can use a calculated field in the SELECT statement. A calculated field can be the result of an arithmetic operation or the result of a string operation. In addition to the standard arithmetic

 
< previous page page_247 next page >

If you like this book, buy it!